Skip to content

runtime: implement weak.runtime_makeStrongFromWeak - #5633

Open
yohimik wants to merge 1 commit into
tinygo-org:devfrom
yohimik:upstream-pr/weak-strong-from-weak
Open

runtime: implement weak.runtime_makeStrongFromWeak#5633
yohimik wants to merge 1 commit into
tinygo-org:devfrom
yohimik:upstream-pr/weak-strong-from-weak

Conversation

@yohimik

@yohimik yohimik commented Aug 30, 2026

Copy link
Copy Markdown

runtime: implement weak.runtime_makeStrongFromWeak

What this does

The runtime has weak.runtime_registerWeakPointer but not its counterpart, so a
program that reads a weak pointer back does not link. The missing function is 7
lines.

Weak pointers are not weak here. registerWeakPointer returns the pointer that
it got, so the value it refers to stays and the way back to a strong pointer is
the identity too. weak.Pointer.Value thus never reports a collected value,
which the documented contract permits.

Evidence

testdata/weak.go makes a weak pointer and reads it back. It is registered in
TestBuild under the minor >= 24 gate, because the weak package came with
Go 1.24.

Measured on macOS 26.6 arm64.

Build Result
current dev link error, weak/pointer.go:89: linker could not find symbol _weak.runtime_makeStrongFromWeak
with this change weak value: 42

The program also builds for cortex-m-qemu, riscv-qemu and simavr.

A downstream product also ships binaries built with a fork that carries this
change, in the published release dispat v1.4.0.
https://github.com/yohimik/dispat/releases/tag/services%2Fdispat%2Fv1.4.0

Why it matters

crypto/tls uses weak.Pointer for its certificate cache, so this is a
prerequisite for the standard library crypto/tls on any target. Any user
program that uses weak hits the same link error today.

Scope

  • One new function in src/runtime/runtime.go. No API change, no behaviour
    change for a program that does not use weak.

Related pull requests

Each open PR in this series has a separate change. A dependency is not a copied commit.

In tinygo-org/net

Full Darwin networking also needs the merged net changes and a later src/net pin update. No upstream merge or current full-suite pass is implied by this list.

Additional independent gaps found in Crier are covered by #5655 (cookie-jar loader merge) and tinygo-org/net#82 (ListenConfig). They do not duplicate the process, TLS, deadline or server-TLS changes above. Current Crier comparison work is separate from its standard-Go release.

Published fork and downstream evidence

The net.2 fork release combines the coordinated changes at 95fba82a, with net 0f460803. It differs from accepted candidate e7d34c8c only in the version constant. Linux, macOS and Windows branch CI and tag CI passed on their first attempts.

Dispat source 909dc401, with harness 0990c6db, passed 796 test events with no failures or skips on each native Darwin ARM64 and Linux ARM64 candidate run. Crier source 7d687fc8 passed raw and stripped E2E on native Linux ARM64 and emulated Linux AMD64, each with 144 top-level tests and 156 passing events, no failures or skips. Both applications use TinyGo-built update fixtures and test trusted TLS, certificate refusal, original backup hashes and byte-identical offline rollback. Their workflows also exercise files, environment variables, concurrency and child processes. Crier includes real FFmpeg and webrender/canvas rendering.

Crier's unchanged 13-image pixel gate passed. It uses an approved two-line explicit-rounding webrender build patch for both compilers. The earlier gradient mismatch was permitted fused arithmetic, not a TinyGo compiler error. Candidate stripped sizes are 13,835,824 versus 30,277,794 Go bytes on ARM64 (54.30% smaller), and 16,446,968 versus 32,518,306 on AMD64 (49.42% smaller).

These are combined-candidate application results, not proof that this PR alone supplies the features. They supersede the earlier Crier comparison. Published-toolchain probes and application acceptance have since completed. The final Crier v1.1.1 release evidence is below. Dispat controls its own publication. WaitDelay, in-flight deadlines and full descriptor lifetime remain open. This enables tested CLI client workflows, not general Go or server compatibility.

Published Crier v1.1.1 evidence

Crier v1.1.1 is public at source acac2f0e and uses published TinyGo 0.43.0-net.2. Its final acceptance report and SHA-256 manifest identify the exact release bytes. The public tag, asset sizes and report digest were checked. These final sizes supersede the candidate sizes above.

Linux target Standard Go bytes Stripped TinyGo bytes Reduction
ARM64 30,277,794 13,835,840 54.30%
AMD64 32,518,306 16,447,000 49.42%

The report records 144 top-level tests and 156 passing events for each raw and stripped run on native ARM64 and emulated AMD64, with no failures or skips. It covers real CLI files, environment and concurrent work, child processes, TLS, update/rollback fixtures, uploads, real FFmpeg, and webrender/canvas rendering. The unchanged 13-image gate passes on both targets. AMD64 is exact; ARM64 has 12 exact images and four event-card pixels with channel difference 1. Both compilers use the same explicit-rounding webrender build patch. Standard Go tests, 90.6% coverage, lint and docs also pass.

This is combined-fork application evidence, not isolated proof for this PR or general server support. The generic emulated AMD64 os closure assertions still fail and also fail with ordinary Go under that emulation; they are not counted as passing. Native AMD64 CI and the final published AMD64 net package pass. The report retains other platform and deadline/descriptor limits. Tiny binaries are opt-in; normal install/self-update selects standard Go assets.

Published Dispat v1.8.1 CLI evidence

Dispat v1.8.1 CLI is public. Its size and SHA-256 manifest records build source 40c58236, Go 1.26.8 and TinyGo 0.43.0-net.2. The public asset metadata and manifest digest were checked.

Linux target Standard Go bytes TinyGo bytes Reduction
ARM64 9,896,098 6,299,032 36.35%
AMD64 10,895,522 6,697,528 38.53%

These are final published CLI asset sizes, not the earlier candidate measurements. They do not replace the separately identified test evidence or remove known runtime limits. The full release workflow has now completed successfully at the recorded build source, including its Windows, macOS and Ubuntu checks. This does not change the test and platform limits stated above.

The runtime had weak.runtime_registerWeakPointer but not its counterpart, so a
program that reads a weak pointer back did not link. crypto/tls does this in
the certificate cache that it keeps behind a weak.Pointer.

Weak pointers are not weak here. registerWeakPointer returns the pointer that
it got, so the value it refers to stays and the way back to a strong pointer is
the identity too. weak.Pointer.Value thus never reports a collected value,
which the documented contract permits.

testdata/weak.go does not link on the current dev branch and prints the
expected value with this change.
@yohimik
yohimik force-pushed the upstream-pr/weak-strong-from-weak branch from 1388449 to 931c476 Compare September 2, 2026 08:50
@yohimik

yohimik commented Sep 2, 2026

Copy link
Copy Markdown
Author

Rebased on dev after the 0.42.0 release. The change applies on top of v0.42.0
as released without a conflict, and the diff is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant